package com.common.core.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.common.core.domain.entity.ProcessConfig;
import com.common.core.mapper.ProcessConfigMapper;
import com.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProcessConfigService  {
    @Autowired
    private ProcessConfigMapper baseMapper;


    /**
     * 通过模块名 查询对应的流程配置类
     *
     * @param moduleName
     * @return  流程key值配置类
     */
    public ProcessConfig getProcessByModelName(String moduleName) {
        try{
            if (StringUtils.isEmpty(moduleName)) return new ProcessConfig();
            LambdaQueryWrapper<ProcessConfig> lqw = new LambdaQueryWrapper();
            lqw.eq(ProcessConfig::getModuleName, moduleName);
            return baseMapper.selectOne(lqw);
        }catch (Exception exception){
            return null;
        }
    }

    /**
     * 通过表名 查询对应的流程key值
     *
     * @param tableName
     * @return 流程key值配置类
     */
    public ProcessConfig getProcessByTableName(String tableName) {
        if (StringUtils.isEmpty(tableName)) return new ProcessConfig();
        LambdaQueryWrapper<ProcessConfig> lqw = new LambdaQueryWrapper();
        lqw.eq(ProcessConfig::getBusinessMainTable, tableName);
        return baseMapper.selectOne(lqw);

    }


    /**
     * 通过ProKey查询对应的实体类
     *
     * @param proKey
     * @return 流程key值配置类
     */
    public ProcessConfig getProcessByProKey(String proKey) {
        if (StringUtils.isEmpty(proKey)) return new ProcessConfig();
        LambdaQueryWrapper<ProcessConfig> lqw = new LambdaQueryWrapper();
        lqw.eq(ProcessConfig::getProcessKey, proKey);
        return baseMapper.selectOne(lqw);

    }


}
